//
//  RootViewController.m
//  FlyingDave
//
//  Created by qianfeng001 on 15/7/8.
//  Copyright (c) 2015年 li. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImageView *view=[[UIImageView alloc]init];
    view.frame=self.view.frame;
    view.image=[UIImage imageNamed:@"back2.jpg"];
    [self.view addSubview:view];
    NSMutableArray*imageArray=[[NSMutableArray alloc]init];
    
    for (int i=1; i<=18; i++) {
        NSString*imageName=[NSString stringWithFormat:@"DOVE %d",i];
        UIImage*image=[UIImage imageNamed:imageName];
        [imageArray addObject:image];
    }
    
    UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    imageView.tag=11;
    imageView.animationImages=imageArray;
    imageView.animationDuration=2;
    [imageView startAnimating];
    [self.view addSubview:imageView];
    NSTimer*timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(startTimer) userInfo:nil repeats:YES];
    [timer setFireDate:[NSDate distantPast]];

}
-(void)startTimer
{
    UIImageView*imageView=(UIImageView*)[self.view viewWithTag:11];
    static int x=1,y=1;
    
    CGRect frame=imageView.frame;
    CGPoint center=imageView.center;
    
    center.x+=x;
    center.y+=y;
    imageView.center=center;
    if (frame.origin.x>self.view.frame.size.width) {
        imageView.center=CGPointMake(0, 40);
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
